#列表解析用于生成元组
print(tuple(x*2 for x in range(5)))
print(tuple(x*2 for x in range(10) if x%2==1))
print('===============================')
#列表解析用于生成集合
print({x for x in range(10)})
print({x for x in range(10) if x%2==1})
print('===============================')
#列表解析用于生成字典
print({x:ord(x) for x in 'abcd'})
print({x:ord(x) for x in 'abcd' if ord(x)%2==0})
print('===============================')
#列表解析用于文件时，每次从文件读取一行数据
mf=open(r'D:\code.txt', encoding='utf-8')
print([x for x in mf])
mf=open(r'D:\code.txt', encoding='utf-8')
print([x.strip() for x in mf])
mf=open(r'D:\code.txt', encoding='utf-8')
print([x.strip() for x in mf if x[0] == 'o'])